<template>
	<view class="box" v-show="show">
		<view class="ws-privacy-popup">
			<view class="ws-privacy-popup__header">
				<view class="ws-picker__title">用户隐私保护提示</view>
			</view>
			<view class="ws-privacy-popup__container">
				<text>感谢您使用本应用，您使用本应用的服务之前请仔细阅读并同意</text>
				<text class="ws-privacy-popup__container-protocol" @click="openPrivacyContract">《小程序隐私保护指引》</text>
				<text>。当您点击同意并开始使用产品服务时，即表示你已理解并同意该条款内容，该条款将对您产生法律约束力。如您拒绝，将无法使用相应服务。</text>
			</view>
			<button id="agree-btn" class="isagree" open-type="agreePrivacyAuthorization"
				@agreeprivacyauthorization="handleAgree">同意</button>
			<button class="isdisagree" id="disagree-btn" type="default" @tap="handleDisagree">
				不同意
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "privacyAgreenPop",
		data() {
			return {
				show: false
			};
		},
		created() {
			wx.getPrivacySetting({
				success: res => {
					console.log("是否需要授权：", res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
					if (res.needAuthorization) {
						// 需要弹出隐私协议
						this.show = true
					} else {
						// 用户已经同意过隐私协议，所以不需要再弹出隐私协议，也能调用已声明过的隐私接口
						this.handleAgree()
					}
				},
				fail: () => {},
				complete: () => {}
			})
		},
		methods: {
			handleAgree() {
				this.$emit("handleAgreeSon")
				this.show = false
			},
			handleDisagree() {
				console.log('1111111111111');
				if (this.goback == 'exit') {
					uni.exitMiniProgram({
						success: () => {
							uni.exitMiniProgram({
								success: (res) => {
									console.log("退出success")
								}
							})
						}
					})
				}
				this.show = false
				this.$emit("handleDisagree")
			},
			/**
			 * 打开隐私协议
			 */
			openPrivacyContract() {
				wx.openPrivacyContract({
					success: (res) => {
						console.log('openPrivacyContract success')
					},
					fail: (res) => {
						console.error('openPrivacyContract fail', res)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		position: fixed;
		left: 0;
		top: 0;
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background-color: #293128;
		z-index: 999;
	}

	.ws-privacy-popup {
		position: absolute;
		left: 50%;
		top: 50%;
		width: 600rpx;
		width: 560rpx;
		padding: 48rpx;
		margin-left: -280rpx;
		margin-top: -290rpx;
		box-sizing: border-box;
		overflow: hidden;
		background: #fff;
		border-radius: 24rpx;

		&__header {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 52rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 550;
			color: #1a1a1a;
			line-height: 52rpx;
			margin-bottom: 48rpx;
		}

		&__container {
			width: 100%;
			box-sizing: border-box;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 48rpx;
			margin-bottom: 48rpx;

			&-protocol {
				font-weight: 550;
				color: #07c160;
			}
		}


		.isdisagree,
		.isagree {
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			border-radius: 44rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			border: 1px solid #07c160;
			font-weight: 400;
			color: #000;
			text-align: center;
			background-color: #fff;
		}

		.isagree {
			background: #07c160;
			color: #ffffff;
			margin-bottom: 18rpx;
		}

		button {
			border: none;
			outline: none;

			&::after {
				border: none;
			}
		}
	}
</style>